package com.elinkway.infinitemovies.http.parser;


import com.elinkway.infinitemovies.bean.AlbumShowBean;
import com.elinkway.infinitemovies.bean.HomePageList;
import com.elinkway.infinitemovies.bigdata.BigDataConstants;
import com.elinkway.infinitemovies.utils.MoviesConstant;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

public class MoreFeedParser extends LVideoMobileParser<HomePageList> {

    @Override
    public HomePageList parse(JSONObject data) throws Exception {
        if (null != data) {
            try {

                HomePageList moreFeedData = new HomePageList();
                ArrayList itemList = new ArrayList();

                JSONArray mArr = data.optJSONArray("data");
                String reid = data.optString("reid");
                String bucket =data.optString("bucket");
                if (null != mArr && mArr.length() > 0) {
                    for (int i = 0; i < mArr.length(); i++) {
                        JSONObject recItemObj = mArr.optJSONObject(i);
                        AlbumShowBean albumShowBean = new AlbumShowBean();
                        getCommonAlbumData(recItemObj, albumShowBean, reid,bucket);
                        albumShowBean.setType(MoviesConstant.MODEL_FEED);
                        albumShowBean.setRecname(BigDataConstants.MORE_FEED_RECNUM);
                        itemList.add(albumShowBean);
                    }
                }

                moreFeedData.setPageItemList(itemList);
                return moreFeedData;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 获取通用的解析数据
     *
     * @param obj
     */
    private void getCommonAlbumData(JSONObject obj, AlbumShowBean albumBean, String reid,String bucket) {
        albumBean.setReid(reid);
        albumBean.setBucket(bucket);
        albumBean.setName(obj.optString("name"));
        albumBean.setAid(obj.optString("aid"));
        albumBean.setThemeid(obj.optString("themeid"));
        albumBean.setPlayurl(obj.optString("playurl"));
        albumBean.setDisplay(obj.optString("display"));
        albumBean.setSubname(obj.optString("subname"));
        albumBean.setPic(obj.optString("pic"));
        albumBean.setPich(obj.optString("pich"));
        albumBean.setVt(obj.optString("vt"));
        albumBean.setShowtime(obj.optString("showtime"));
        albumBean.setNowepisodes(obj.optString("nowepisodes"));
        albumBean.setPicsize(obj.optString("picsize"));
        albumBean.setEpisodes(obj.optString("episodes"));
        albumBean.setIsend(obj.optString("isend"));
        albumBean.setRating(obj.optString("rating"));
        albumBean.setCategoryname(obj.optString("category_name"));
        albumBean.setDescription(obj.optString("description"));
        albumBean.setPlaycount(obj.optString("play_count"));
        albumBean.setInfo(obj.optString("info"));

        albumBean.setCornerColor(obj.optString("cornerColor"));
        albumBean.setCornerTitle(obj.optString("cornerTitle"));
        albumBean.setEposidesInfo(albumBean.getEpisodeInfoInString());
    }

}
